{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python37764bit5d211478a4cf4a3d93a2c891f6a9207d",
   "display_name": "Python 3.7.7 64-bit"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "{&#39;orange&#39;, &#39;pear&#39;, &#39;apple&#39;}\n"
    }
   ],
   "source": [
    "'''\n",
    "Python也包含有 集合 类型。集合是由不重复元素组成的无序的集。它的基本用法包括成员检测和消除重复元素。集合对象也支持像 联合，交集，差集，对称差分等数学运算。\n",
    "花括号或 set() 函数可以用来创建集合。注意：要创建一个空集合你只能用 set() 而不能用 {}，因为后者是创建一个空字典，这种数据结构我们会在下一节进行讨论。\n",
    "'''\n",
    "\n",
    "basket = {'apple', 'orange', 'pear', 'orange', 'apple'}\n",
    "print(basket)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "True"
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "source": [
    "'orange' in basket"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;n&#39;, &#39;r&#39;}"
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "source": [
    "a = set('abrancadaber')\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{&#39;a&#39;, &#39;b&#39;, &#39;c&#39;}"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "b = set('abc')\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{&#39;d&#39;, &#39;e&#39;, &#39;n&#39;, &#39;r&#39;}"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "a - b  # 非"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;n&#39;, &#39;r&#39;}"
     },
     "metadata": {},
     "execution_count": 6
    }
   ],
   "source": [
    "a|b  # 或"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{&#39;a&#39;, &#39;b&#39;, &#39;c&#39;}"
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "source": [
    "a & b  # 且"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "{&#39;d&#39;, &#39;e&#39;, &#39;n&#39;, &#39;r&#39;}"
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "source": [
    "a ^ b #  in a or b but not both"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}